/**
 * AJAX服务
 * @type {{}}
 *
 * Created by anr on 2017/12/4.
 */
let data = {};

const HTTP_URL = 'http://www.openwater.com.cn/api/index';

let ajaxHttp = function(key) {
  try {
    return $.ajax({
      url: HTTP_URL + key,
      dataType: 'json',
      error: function(error) {
        console.log(error.statusText + ':' + error.status);
      }
    });
  } catch (error) {
    return null;
  }
};

export default {
  get(key, p = '') {
    return new Promise((rev, rej) => {
      //TODO 这里改为接口访问
      key = p != '' ? `/${p}?p=${key}` : key;
      rev(ajaxHttp(key));
      // data.hasOwnProperty(key) ? rev(ajaxHttp(key)) : rej({code: 404, msg: 'can not attach API: ' + key});
    });
  }
};
